package com.kakarote.admin.service.impl;

import com.kakarote.admin.entity.PO.AdminDataAuthDept;
import com.kakarote.admin.mapper.AdminDataAuthDeptMapper;
import com.kakarote.admin.service.IAdminDataAuthDeptService;
import com.kakarote.core.servlet.BaseServiceImpl;
import com.kakarote.core.utils.UserUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 数据权限和部门关联表 服务实现类
 * </p>
 *
 * @author lizhihui
 * @since 2023-10-17
 */
@Service
public class AdminDataAuthDeptServiceImpl extends BaseServiceImpl<AdminDataAuthDeptMapper, AdminDataAuthDept> implements IAdminDataAuthDeptService {

    @Override
    public void saveDataAuthDept(List<AdminDataAuthDept> authDeptList, Long roleId) {
        List<AdminDataAuthDept> adminDataAuthDeptList = new ArrayList<>();
        for (AdminDataAuthDept authDept : authDeptList) {
            AdminDataAuthDept adminDataAuthDept = new AdminDataAuthDept();
            adminDataAuthDept.setDeptId(authDept.getDeptId());
            adminDataAuthDept.setRoleId(roleId);
            adminDataAuthDeptList.add(adminDataAuthDept);
        }
        saveBatch(adminDataAuthDeptList);
    }

    @Override
    public List<AdminDataAuthDept> queryDeptByRoleId(Long roleId) {
        return getBaseMapper().queryDeptByRoleId(roleId);
    }
}
